// 云函数入口函数
const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database();
const _ = db.command
exports.main = async (event, context) => {
  const { _id, openid,name } = event;

  try {
    // 使用传入的 _id 来执行更新操作
    await db.collection('dormitory').doc(_id).update({
      data: {
        member: _.push({openid,name})
      }
    });

    return {
      success: true
    };
  } catch (err) {
    return {
      success: false,
      errMsg: err.message
    };
  }
}
